package com.pudu.mydemo.fragment;

import android.app.DialogFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.InputType;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.pudu.mydemo.utils.WiFiConnecter;
import com.pudutech.pdrobot.R;

/**
 * Created by guiliu on 2016/7/20.
 */
public class WifiLoginDialogFragment extends DialogFragment{
    private String Tag = this.getClass().getSimpleName();
    private ImageView cancel ,ok ;
    private EditText password;
    private TextView wifiname;
    private WiFiConnecter wifiConnecter;
    private   String ssid;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.wifi_login_dialog, container);
        cancel = (ImageView)view.findViewById(R.id.cancel);
        ok = (ImageView)view.findViewById(R.id.ok);
        password = (EditText)view.findViewById(R.id.password);
        wifiname = (TextView)view.findViewById(R.id.wifi_name);
//        wifiConnecter = new WiFiConnecter(getActivity());
        Bundle bundle = getArguments();
        boolean isconfig  = bundle.getBoolean("isConfig");
        ssid = bundle.getString("ssid","");
        Log.e(Tag,"isconfig"+isconfig+" ssid:"+ssid);
        wifiname.setText(ssid);
        if(isconfig){
           /* password.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
            password.setText("123456");
            Toast.makeText(getActivity(),"已经配置了，请重新输入密码",Toast.LENGTH_LONG).show();*/
        }

        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoginInputListener listener = (LoginInputListener) getActivity();
                listener.onLoginInputComplete(ssid,password
                        .getText().toString());
                dismiss();
            }
        });

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        return view;
    }

    public interface LoginInputListener
    {
        void onLoginInputComplete(String ssid, String password);
    }
}
